<?php

use Attend as GlobalAttend;

defined('BASEPATH') or exit('No direct script access allowed');

class Attend extends WxHomeController
// class Attend extends MY_Controller
{
    public function __construct() {
        parent::__construct();
        $this->load->model("Admin_model");
        $this->load->model("Attend_model");
        $this->load->model("Attend_student_status_model");
        $this->load->model("Attend_teaching_content_model");
        $this->load->model("Attend_teaching_implementation_model");
        $this->load->model("Attend_img_model");
        $this->load->model('Student_feedback_model');
        $this->load->model('Supervisor_feedback_model');
        $this->load->model('Other_statistics_model');
        $this->load->model('Supervisor_feedback_record_model');
        $this->load->model('Student_feedback_record_model');
    }



    public function Index() {
        $this->load->view('home/supervision_mobile');
    }
    public function statistical() {
        $data['identity']=$this->identity($_SESSION[SESS_USER_HOME]);
        $this->load->view('home/statistical',$data);
    }
    public function lists() {
        $data['identity']=$this->identity($_SESSION[SESS_USER_HOME]);
        $this->load->view('home/list',$data);
    }
    public function feedback() {
        $data['identity']=$this->identity($_SESSION[SESS_USER_HOME]);
        $this->load->view('home/feedback',$data);
    }
    public function record() {
        $this->load->view('home/record');
    }
    public function details() {
        $this->load->view('home/details');
    }
    public function feedback_ist() {
        $data['identity']=$this->identity($_SESSION[SESS_USER_HOME]);
        $this->load->view('home/feedback_ist',$data);
    }
    public function other() {
        $this->load->view('home/other');
    }
    public function supervision() {
        $this->load->view('home/supervision');
    }
    public function feedback_inf() {
        $this->load->view('home/feedback_inf');
    }


    /**
     * 方法名 attendList
     *
     * @Name attendList
     * @Desc 听课记录列表
     * @OpenFlag 是否开放,1开放0权限控制
     * @Author      zn
     * @Date 2021-07-22 09:50:06 星期四
     * @return      [type]                   [description]
     */
    public function attendList() {
        if (!isset($_POST['listen_id'], $_POST['pageNo'], $_POST['pageSize'])) {
            exit(retJson('参数错误', false));
        }

        $con = array(
            'where'    => $this->sqlLikeEscape("listen_id = ??", array($_POST['listen_id'])),
            'items'    => 'id, class_name, score, listen_type, type, created, teacher_code',
            'orderby'  => 'created desc',
            'pageNo'   => $_POST['pageNo'],
            'pageSize' => $_POST['pageSize'],
        );
        $list = $this->Attend_model->get_page_list($con);

        foreach ($list['ret'] as $key => $value) {
            $list['ret'][$key]['attendType'] = (new AttendType())->show($value['type']);
            $list['ret'][$key]['created']    = date('Y-m-d H:i:s', $value['created']);
        }

        // pri($list);exit();
        exit(retJson('请求成功', true, $list));
    }

    /**
     * 方法名 attendInfo
     *
     * @Name attendInfo
     * @Desc 听课记录详情
     * @OpenFlag 是否开放,1开放0权限控制
     * @Author      zn
     * @Date 2021-07-22 09:50:06 星期四
     * @return      [type]                   [description]
     */
    public function attendInfo() {
        if (!isset($_POST['aid'])) {
            exit(retJson('参数错误', false));
        }

        $con = array(
            'where' => $this->sqlLikeEscape("id = ??", array($_POST['aid'])),
            'items' => 'class_name, listen_address, listen_class, advice, created, score',
        );
        $info = $this->Attend_model->get_single_full($con);
        if (!isset($info)) {
            exit(retJson('当前记录不存在!', false));
        }


        // $student_status            		 = $this->getInfo('get_score', $_POST['aid'], $this->Attend_student_status_model);
        // $teaching_content          		 = $this->getInfo('get_score', $_POST['aid'], $this->Attend_teaching_content_model);
        // $teaching_implementation   		 = $this->getInfo('get_score', $_POST['aid'], $this->Attend_teaching_implementation_model);
        $img                                = $this->getInfo('img', $_POST['aid'], $this->Attend_img_model);
        // $info['student_status']          = $student_status['get_score'];
        // $info['teaching_content']        = $teaching_content['get_score'];
        // $info['teaching_implementation'] = $teaching_implementation['get_score'];
        $info['img']                     = $img['img'];
        $info['created']                 = date('Y-m-d H:i:s', $info['created']);

        // pri($info);exit();
        exit(retJson('请求成功', true, $info));
    }

    private function getInfo($item, $attend_id, $model) {
        $con = array(
            'where' => $this->sqlLikeEscape("attend_id = ??", array($attend_id)),
            'items' => $item,
        );
        return $model->get_single_full($con);
    }


    // 获取身份
    private function identity($user) {
        $idtt = explode(',', $user['sub_role_id']);
        array_push($idtt, $user['role_id']);
        if (in_array(13, $idtt)) {
            // 管理员
            return $identity = 1;
        }
        if (in_array(5, $idtt)) {
            // 二级督导组长
            return $identity = 2;
        }
        if (in_array(6, $idtt) || in_array(4, $idtt) || in_array(2, $idtt)) {
            // 二级督导/校督导/教师
            return $identity = 3;
        }
        return 0;
    }

    /**
     * 方法名 teachingEvaluationList
     *
     * @Name 获取方法列和角色方法列
     * @Desc 课堂教学评价列表
     * @OpenFlag 是否开放,1开放0权限控制
     * @Author      zn
     * @Date 2021-07-22 11:13:54 星期四
     * @return      [type]                   [description]
     */
    public function teachingEvaluationList() {
        if (!isset($_POST['admin_id'], $_POST['pageNo'], $_POST['pageSize'])) {
            exit(retJson('参数错误', false));
        }

        $con = array(
            // 'where'    => $this->sqlLikeEscape("teacher_code = ??", array($_POST['teacher_code'])),
            'where'    => '1 = 1',
            'items'    => 'id,class_name, score, listen_type, type, created, advice, teacher_name, teacher_code, listen_name, course_units',
            'orderby'  => 'created desc',
            'pageNo'   => $_POST['pageNo'],
            'pageSize' => $_POST['pageSize'],
        );


        // 身份筛选
        $user = $this->Admin_model->get_single(array('id' => $_POST['admin_id']));
        $identity = $this->identity($user);
        $con['where']=$this->sqlEscape("status=?? ", array(AttendStatus::Submit[XPHEnum::Value]));
        if ($identity == 3) {
            // 二级督导/校督导/教师
            $con['where'].= $this->sqlLikeEscape(" and (teacher_code = ?? or listen_id = ??) ", array($user['usercode'], $user['id']));
        } elseif ($identity == 2) {
            // 二级督导组长
            $c = array(
                'where' => $this->sqlLikeEscape(" dept_id = ?? and ( role_id in (5, 6) or FIND_IN_SET(5, sub_role_id) or FIND_IN_SET(6, sub_role_id)) ", array($user['dept_id'])),
                'items'  => 'id, role_id, sub_role_id',
            );
            $users = $this->Admin_model->get_list_full($c);
            $in = '';
            foreach ($users as $key => $value) {
                $in .= $value['id'] . ',';
            }

            $con['where'].= $this->sqlLikeEscape(" and (listen_id in (??) )", array(rtrim($in, ',')));
        }


        // 筛选
        if (isset($_POST['created']) && !empty($_POST['created'])) {
            $time = date('Y-m-d', strtotime($_POST['created']));
            $start = strtotime($time);
            $end   = strtotime('+1 day', $start);
            $con['where'] .= $this->sqlLikeEscape(" and created >=?? and created <=??", array($start, $end));
        }
        if ($identity != 2 && isset($_POST['course_units']) && !empty($_POST['course_units'])) {
            // 督导组长无法筛选
            $con['where'] .= $this->sqlLikeEscape(" and course_units = '??'", array($_POST['course_units']));
        }
        if (isset($_POST['listen_type'])&& !empty($_POST['listen_type'])) {
            $con['where'] .= $this->sqlLikeEscape(" and listen_type = '??'", array($_POST['listen_type']));
        }
        if (isset($_POST['type'])&& !empty($_POST['type'])) {
            $con['where'] .= $this->sqlLikeEscape(" and type = ??", array($_POST['type']));
        }


        $list = $this->Attend_model->get_page_list($con);
        foreach ($list['ret'] as $key => $value) {
            $list['ret'][$key]['attendType'] = (new AttendType())->show($value['type']);
            $list['ret'][$key]['created'] = date('Y-m-d H:i:s', $value['created']);
        }

        // echo $this->db->last_query();
        // pri($list);
        // exit();
        exit(retJson('请求成功', true, $list));
    }


    /**
     * 方法名 teachingEvaluationStatistics
     *
     * @Name teachingEvaluationStatistics
     * @Desc 课堂教学评价统计
     * @OpenFlag 是否开放,1开放0权限控制
     * @Author      zn
     * @Date 2021-07-22 11:13:54 星期四
     * @return      [type]                   [description]
     */
    public function teachingEvaluationStatistics() {
        if (!isset($_POST['admin_id'], $_POST['pageNo'], $_POST['pageSize'])) {
            exit(retJson('参数错误', false));
        }

        $con1 = array(
            'where'    => "teacher_code != '暂无工号' ",
            'items'    => 'id, teacher_code',
            'groupby'  => 'teacher_code',
            'orderby'  => 'id asc',
            'pageNo'   => $_POST['pageNo'],
            'pageSize' => $_POST['pageSize'],
        );


        // 身份筛选
        $user = $this->Admin_model->get_single(array('id' => $_POST['admin_id']));
        $identity = $this->identity($user);
        if ($identity == 3) {
            // 二级督导/校督导/教师
            exit(retJson('暂无数据', true, array()));
        } elseif ($identity == 2) {
            // 二级督导组长
            // $c = array(
            //     'where' => $this->sqlLikeEscape(" dept_id = ?? and ( role_id in (5, 6) or FIND_IN_SET(5, sub_role_id) or FIND_IN_SET(6, sub_role_id)) ", array($user['dept_id'])),
            //     'items'  => 'id, role_id, sub_role_id',
            // );
            // $users = $this->Admin_model->get_list_full($c);
            // $in = '';
            // foreach ($users as $key => $value) {
            //     $in .= $value['id'] . ',';
            // }

            // $con1['where'] = $this->sqlLikeEscape(" listen_id in (??) ", array(rtrim($in, ',')));
            $con1['where'] = $this->sqlLikeEscape(" course_units = '??'", array(str_replace('分', '学', $user['dept_name'])));
        }


        // 筛选
        if (isset($_POST['created']) && !empty($_POST['created'])) {
            $time = date('Y-m-d', strtotime($_POST['created']));
            $start = strtotime($time);
            $end   = strtotime('+1 day', $start);
            $con1['where'] .= $this->sqlLikeEscape(" and created >=?? and created <=??", array($start, $end));
        }
        if ($identity != 2 && isset($_POST['course_units']) && !empty($_POST['course_units'])) {
            // 督导组长无法筛选
            $con1['where'] .= $this->sqlLikeEscape(" and course_units = '??'", array($_POST['course_units']));
        }
        if (isset($_POST['listen_type']) && !empty($_POST['listen_type'])) {
            $con1['where'] .= $this->sqlLikeEscape(" and listen_type = '??'", array($_POST['listen_type']));
        }
        if (isset($_POST['type']) && !empty($_POST['type'])) {
            $con1['where'] .= $this->sqlLikeEscape(" and type = ??", array($_POST['type']));
        }
        $teachers = $this->Attend_model->get_list_full($con1);
        // echo $this->db->last_query();
        // pri($teachers);
        // exit();

        if (empty($teachers)) {
            exit(retJson('暂无数据', false));
        }

        // 总数
        $where = $con1['where'];
        $cot = "SELECT count(*) AS count FROM
                    (SELECT id
                    FROM `db_attend`
                    WHERE $where
                    GROUP BY `teacher_code`) AS t";
        $ret = $this->Attend_model->query($cot);
        $list['count'] = $ret[0]['count'];
        //总页数
        $list["totalPage"] = ceil($list["count"] / $_POST['pageSize']);
        $list["pageNo"] = $_POST['pageNo'];


        // 每个教师统计信息
        $con = array(
            'items'   => 'type, COUNT(*) AS count, CAST(AVG(score) AS DECIMAL(10,2)) AS avg_score',
            'groupby' => 'type',
            'orderby' => 'type asc',
        );
        foreach ($teachers as $key => $value) {
            $all = array(
                'items' => 'course_units, teacher_code, teacher_name, CAST(AVG(score) AS DECIMAL(10,2)) AS all_avg_score',
                'where' => $this->sqlLikeEscape("teacher_code = ?? and status=??", array($value['teacher_code'],AttendStatus::Submit[XPHEnum::Value])),
            );
            $list['ret'][$key] = $this->Attend_model->get_single_full($all); // 总平均分
            // echo $this->db->last_query();echo "<br/>";

            $con['where'] = $this->sqlLikeEscape("teacher_code = ?? and status=??", array($value['teacher_code'],AttendStatus::Submit[XPHEnum::Value]));
            $list['ret'][$key]['detail'] = $this->Attend_model->get_list_full($con);
        }
        // type转化
        foreach ($list['ret'] as $key => $value) {
            foreach ($value['detail'] as $k => $v) {
                if ($v['type'] == 1) {
                    $list['ret'][$key]['detail'][$k]['type_info'] = '校督导';
                } elseif ($v['type'] == 2) {
                    $list['ret'][$key]['detail'][$k]['type_info'] = '二级督导';
                } elseif ($v['type'] == 3) {
                    $list['ret'][$key]['detail'][$k]['type_info'] = '外聘督导';
                }
            }
        }

        // pri($list);
        // exit();
        exit(retJson('请求成功', true, $list));
    }



    /**
     * 方法名 informationFeedback
     *
     * @Name informationFeedback
     * @Desc 信息反馈统计报表
     * @OpenFlag 是否开放,1开放0权限控制
     * @Author      zn
     * @Date 2021-07-22 11:13:54 星期四
     * @return      [type]                   [description]
     */
    public function informationFeedback() {
        if (!isset($_POST['pageNo'], $_POST['pageSize'])) {
            exit(retJson('参数错误', false));
        }
        $pageNo = ($_POST['pageNo'] - 1) * $_POST['pageSize'];
        $pageSize = $_POST['pageSize'];
        
        $identity = $this->identity($_SESSION[SESS_USER_HOME]);
        $where=$this->sqlLikeEscape(" where del_flag=??", array(CommonWhether::Whether[XPHEnum::Value]));
        if ($identity == 3) {
            // 二级督导/校督导/教师
            $where.=" and 1<>1";
        } elseif ($identity == 2) {
            // 二级督导组长
            $where.= $this->sqlEscape(" and feedback.dept_name = ?? ", array($_SESSION[SESS_USER_HOME]['dept_name']));        
        }

        if (isset($_POST['created']) && !empty($_POST['created'])) {
            $time = date('Y-m-d', strtotime($_POST['created']));
            $start = strtotime($time);
            $end   = strtotime('+1 day', $start);
            $where .= $this->sqlLikeEscape(" and feedback.created >=?? and feedback.created <= ??", array($start, $end));
        }
        if (isset($_POST['dept_name']) && !empty($_POST['dept_name'])) {
            $where .= $this->sqlEscape(" and db_admin.dept_name=??", array($_POST['dept_name']));
        }
;

        //总数
        $cot = "SELECT count(*) AS count FROM (SELECT db_admin.id
                FROM
                (SELECT creator,del_flag,dept_name,created FROM db_student_feedback UNION ALL SELECT creator,del_flag,dept_name,created FROM db_supervisor_feedback ) feedback
                LEFT JOIN db_admin ON db_admin.id = feedback.creator".$where." GROUP by feedback.creator) AS cot";
        $ret = $this->Student_feedback_model->query($cot);
        $list['count'] = $ret[0]['count'];
        //总页数
        $list["totalPage"] = ceil($list["count"] / $pageSize);
        $list["pageNo"] = $_POST['pageNo'];

        // 数据
        $sql = "SELECT count(*) AS count,username,db_admin.dept_name,feedback.created AS created_time,creator
                FROM
                ( SELECT creator,created,del_flag,dept_name FROM db_student_feedback UNION ALL SELECT creator,created,del_flag,dept_name FROM db_supervisor_feedback ) feedback
                LEFT JOIN db_admin ON db_admin.id = feedback.creator
                ".$where."
                GROUP BY feedback.creator
                ORDER BY feedback.created DESC
                LIMIT $pageNo, $pageSize";
        $list['ret'] = $this->Student_feedback_model->query($sql);
        $list['all_count'] = array_sum(array_column($list['ret'], 'count'));

        // pri($list);exit();
        // echo $this->db->last_query();
        // exit();


        // $con = array(
        //     'items'    => 'ad.dept_name, count(*) as count, ad.username',
        //     'groupby'  => 'creator',
        //     'orderby'  => 'db_student_feedback.id asc',
        //     'join'     =>  array('db_admin ad', 'ad.id = db_student_feedback.creator'),
        //     'pageNo'   => $_POST['pageNo'],
        //     'pageSize' => $_POST['pageSize'],
        // );

        // $stu = $this->Student_feedback_model->get_list_full($con);
        // $con['join'] = array('db_admin ad', 'ad.id = db_supervisor_feedback.creator');
        // $con['orderby'] = 'db_supervisor_feedback.id asc';
        // $sup = $this->Supervisor_feedback_model->get_list_full($con);
        // $list = array_merge($stu, $sup);

        exit(retJson('请求成功', true, $list));
    }


    /**
     * 方法名 FeedbackList
     *
     * @Name FeedbackList
     * @Desc 信息反馈列表
     * @OpenFlag 是否开放,1开放0权限控制
     * @Author      zn
     * @Date 2021-07-22 11:13:54 星期四
     * @return      [type]                   [description]
     */
    public function feedbackList() {
        if (!isset($_POST['pageNo'], $_POST['pageSize'], $_POST['admin_id'])) {
            exit(retJson('参数错误', false));
        }

        // pri($_POST);exit();
        // 身份筛选
        $user = $this->Admin_model->get_single(array('id' => $_POST['admin_id']));
        $identity = $this->identity($user);
        if ($identity == 3) {
            // 二级督导/校督导/教师
            exit(retJson('暂无数据', true, array()));
        } elseif ($identity == 2) {
            // 二级督导组长
            $where1 = $this->sqlLikeEscape("db_supervisor_feedback.dept_name = '??' and del_flag='??'", array($user['dept_name'],CommonStatus::UnDeleted[XPHEnum::Value]));
            $where2 = $this->sqlLikeEscape("db_student_feedback.dept_name = '??'  and del_flag='??'", array($user['dept_name'],CommonStatus::UnDeleted[XPHEnum::Value]));
        } else {
            $where1 = '1 = 1 and del_flag='.CommonStatus::UnDeleted[XPHEnum::Value];
            $where2 = '1 = 1 and del_flag='.CommonStatus::UnDeleted[XPHEnum::Value];
        }

        // 筛选
        if (isset($_POST['created']) && !empty($_POST['created'])) {
            $time = date('Y-m-d', strtotime($_POST['created']));
            $start = strtotime($time);
            $end   = strtotime('+1 day', $start);
            $where1 .= $this->sqlLikeEscape(" and db_supervisor_feedback.created >=?? and db_supervisor_feedback.created <= ??", array($start, $end));
            $where2 .= $this->sqlLikeEscape(" and db_student_feedback.created >=?? and db_student_feedback.created <= ??", array($start, $end));
        }
        if (isset($_POST['creator']) && !empty($_POST['creator'])) {
            $where1 .= $this->sqlEscape(" and db_supervisor_feedback.creator=??", array($_POST['creator']));
            $where2 .= $this->sqlEscape(" and db_student_feedback.creator = ??", array($_POST['creator']));
        }
        if ($identity != 2 && isset($_POST['dept_name']) && !empty($_POST['dept_name'])) {
            // 督导组长无法筛选
            $where1 .= $this->sqlLikeEscape(" and db_supervisor_feedback.creator = '??'", array($_POST['dept_name']));
            $where2 .= $this->sqlLikeEscape(" and db_student_feedback.dept_name = '??'", array($_POST['dept_name']));
        }



        $pageNo = ($_POST['pageNo'] - 1) * $_POST['pageSize'];
        $pageSize = $_POST['pageSize'];
        //总数
        $cot = "SELECT count(*) AS count FROM
                    (SELECT `ad`.`dept_name`, `ad`.`username`, `category`, `content`, `db_supervisor_feedback`.`created`
                        FROM `db_supervisor_feedback`
                        LEFT JOIN `db_admin` `ad` ON `db_supervisor_feedback`.`creator` = `ad`.`id`
                        WHERE $where1
                    UNION ALL
                    SELECT `ad`.`dept_name`, `ad`.`username`, `category`, `content`, `db_student_feedback`.`created`
                        FROM `db_student_feedback`
                        LEFT JOIN `db_admin` `ad` ON `db_student_feedback`.`creator` = `ad`.`id`
                        WHERE $where2
                    ) AS feedback";
        $ret = $this->Student_feedback_model->query($cot);
        $list['count'] = $ret[0]['count'];

        //总页数
        $list["totalPage"] = ceil($list["count"] / $pageSize);
        $list["pageNo"] = $_POST['pageNo'];

        // 数据
        $sql = "SELECT * FROM
                    (SELECT `ad`.`dept_name`, `ad`.`username`, `category`, `content`, `db_supervisor_feedback`.`created`
                        FROM `db_supervisor_feedback`
                        LEFT JOIN `db_admin` `ad` ON `db_supervisor_feedback`.`creator` = `ad`.`id`
                        WHERE $where1
                    UNION ALL
                    SELECT `ad`.`dept_name`, `ad`.`username`, `category`, `content`, `db_student_feedback`.`created`
                        FROM `db_student_feedback`
                        LEFT JOIN `db_admin` `ad` ON `db_student_feedback`.`creator` = `ad`.`id`
                        WHERE $where2
                    ) AS feedback
                ORDER BY feedback.created DESC
                LIMIT $pageNo, $pageSize";
        $list['ret'] = $this->Student_feedback_model->query($sql);
        // echo $this->db->last_query();



        foreach ($list['ret'] as $key => $value) {
            $list['ret'][$key]['created'] = date('Y-m-d H:i:s', $value['created']);
        }
        // pri($list);
        // exit();
        exit(retJson('请求成功', true, $list));
    }



    /**
     * 方法名 otherStatistics
     *
     * @Name otherStatistics
     * @Desc 其他材料统计报表
     * @OpenFlag 是否开放,1开放0权限控制
     * @Author      zn
     * @Date 2021-07-26 15:47:59 星期一
     * @return      [type]                   [description]
     */
    public function otherStatistics() {
        if (!isset($_POST['pageNo'], $_POST['pageSize'], $_POST['admin_id'])) {
            exit(retJson('参数错误', false));
        }

        $con = array(
            'where'    => '1 = 1',
            'items'    => 'username, dept_name, specialResearch, patrol, tourInformant, specialInspection, postPractice, messenger',
            'pageNo'   => $_POST['pageNo'],
            'pageSize' => $_POST['pageSize'],
        );

        // 身份筛选
        $user = $this->Admin_model->get_single(array('id' => $_POST['admin_id']));
        $identity = $this->identity($user);
        if ($identity == 3) {
            // 二级督导/校督导/教师
            exit(retJson('暂无数据', true, array()));
        } elseif ($identity == 2) {
            $con['where'] = $this->sqlLikeEscape("dept_name = '??'", array($user['dept_name']));
        }

        $list = $this->Other_statistics_model->get_page_list($con);
        $list['all_count'] = array(
            'specialResearch'   => array_sum(array_column($list['ret'], 'specialResearch')),
            'patrol'            => array_sum(array_column($list['ret'], 'patrol')),
            'tourInformant'     => array_sum(array_column($list['ret'], 'tourInformant')),
            'specialInspection' => array_sum(array_column($list['ret'], 'specialInspection')),
            'postPractice'      => array_sum(array_column($list['ret'], 'postPractice')),
            'messenger'         => array_sum(array_column($list['ret'], 'messenger')),
        );
        // pri($list);
        // exit();
        exit(retJson('请求成功', true, $list));
    }

    // public function otherStatistics1()
    // {
    //     if (!isset($_POST['pageNo'], $_POST['pageSize'], $_POST['admin_id'])) {
    //         exit(retJson('参数错误', false));
    //     }

    //     $con = array(
    //         'where'    => '1 = 1',
    //         'items'    => 'username, dept_name, count(*) as count, admin_id',
    //         'groupby'  => 'admin_id',
    //         // 'pageNo'   => $_POST['pageNo'],
    //         // 'pageSize' => $_POST['pageSize'],
    //     );


    //     // 身份筛选
    //     $user = $this->Admin_model->get_single(array('id' => $_POST['admin_id']));
    //     $identity = $this->identity($user);
    //     if ($identity == 3) {
    //         // 二级督导/校督导/教师
    //         exit(retJson('暂无数据', true, array()));
    //     } elseif ($identity == 2) {
    //         $con['where'] = $this->sqlLikeEscape("a.dept_name = '??'", array($user['dept_name']));
    //     }


    //     $con['join'] = array('db_admin as a', 'db_table1.admin_id = a.id');
    //     $specialResearch = $this->Table1_model->get_list_full($con);

    //     $con['join'] = array('db_admin as a', 'db_table2.admin_id = a.id');
    //     $patrol = $this->Table2_model->get_list_full($con);

    //     $con['join'] = array('db_admin as a', 'db_table3.admin_id = a.id');
    //     $tourInformant = $this->Table3_model->get_list_full($con);

    //     $con['join'] = array('db_admin as a', 'db_table4.admin_id = a.id');
    //     $specialInspection = $this->Table4_model->get_list_full($con);

    //     $con['join'] = array('db_admin as a', 'db_table5.admin_id = a.id');
    //     $postPractice = $this->Table5_model->get_list_full($con);

    //     $con['join'] = array('db_admin as a', 'db_table6.admin_id = a.id');
    //     $messenger = $this->Table6_model->get_list_full($con);

    //     // 用户名作为键名
    //     $a = array_column($specialResearch, null, 'username');
    //     $b = array_column($patrol, null, 'username');
    //     $c = array_column($tourInformant, null, 'username');
    //     $d = array_column($specialInspection, null, 'username');
    //     $e = array_column($postPractice, null, 'username');
    //     $f = array_column($messenger, null, 'username');

    //     // pri($c);
    //     // exit();
    //     $users = array_column($tourInformant, 'username');
    //     foreach ($users as $key => $value) {
    //         $list[$key] = array(
    //             'username'          => $value,
    //             'admin_id'          => $c[$value]['admin_id'],
    //             'dept_name'         => $c[$value]['dept_name'],
    //             'specialResearch'   => array_key_exists($value, $a) ? $a[$value]['count'] : 0 ,
    //             'Patrol'            => array_key_exists($value, $b) ? $b[$value]['count'] : 0 ,
    //             'tourInformant'     => array_key_exists($value, $c) ? $c[$value]['count'] : 0 ,
    //             'specialInspection' => array_key_exists($value, $d) ? $d[$value]['count'] : 0 ,
    //             'postPractice'      => array_key_exists($value, $e) ? $e[$value]['count'] : 0 ,
    //             'messenger'         => array_key_exists($value, $f) ? $f[$value]['count'] : 0 ,
    //         );
    //     }

    //     $this->Other_statistics_model->add_batch($list);

    //     pri($list);
    //     exit();
    //     exit(retJson('请求成功', true, $list));
    // }



    /**
     * 方法名 teacherFeedBack
     *
     * @Name teacherFeedBack
     * @Desc 信息反馈（教师查看反馈给自己的内容）
     * @OpenFlag 是否开放,1开放0权限控制
     * @Author      zn
     * @Date 2021-07-26 15:47:59 星期一
     * @return      [type]                   [description]
     */
    public function teacherFeedBack() {
        if (!isset($_POST['admin_id'], $_POST['pageNo'], $_POST['pageSize'])) {
            exit(retJson('参数错误', false));
        }


        $admin_id = $_POST['admin_id'];
        $pageNo = ($_POST['pageNo'] - 1) * $_POST['pageSize'];
        $pageSize = $_POST['pageSize'];

        // 总数
        $cot = "SELECT count(*) as count FROM
                (
                    SELECT stu.created,stu.content FROM db_student_feedback_record LEFT JOIN db_student_feedback AS stu
                        ON db_student_feedback_record.feedback_id = stu.id WHERE admin_id = $admin_id
                    UNION ALL
                    SELECT sup.created,sup.content FROM db_supervisor_feedback_record LEFT JOIN db_supervisor_feedback AS sup
                        ON db_supervisor_feedback_record.feedback_id = sup.id WHERE admin_id = $admin_id
                ) AS record";
        $ret = $this->Student_feedback_record_model->query($cot);
        $list['count'] = $ret[0]['count'];

        //总页数
        $list["totalPage"] = ceil($list["count"] / $pageSize);
        $list["pageNo"] = $_POST['pageNo'];


        // 数据
        $sql = "SELECT * FROM
                (
                    SELECT stu.created,stu.content FROM db_student_feedback_record LEFT JOIN db_student_feedback AS stu
                        ON db_student_feedback_record.feedback_id = stu.id WHERE admin_id = $admin_id
                    UNION ALL
                    SELECT sup.created,sup.content FROM db_supervisor_feedback_record LEFT JOIN db_supervisor_feedback AS sup
                        ON db_supervisor_feedback_record.feedback_id = sup.id WHERE admin_id = $admin_id
                ) AS record
                ORDER BY record.created DESC
                LIMIT $pageNo, $pageSize";
        $ret = $this->Student_feedback_record_model->query($sql);
        foreach ($ret as $key => $value) {
            $ret[$key]['created'] = date('Y-m-d h:i:s', $value['created']);
        }
        $list['ret'] = $ret;

        // echo $this->db->last_query();
        // pri($list);exit();
        exit(retJson('请求成功', true, $list));
    }



    public function teachingScreen() {
        $sql = "SELECT listen_type FROM db_attend WHERE listen_type IS NOT NULL GROUP BY listen_type ";
        $res1 = $this->Attend_model->query($sql);
        $screen['listen_type'] = array_column($res1, 'listen_type');
        $sql = "SELECT course_units FROM db_attend WHERE course_units IS NOT NULL GROUP BY course_units ";
        $res2 = $this->Attend_model->query($sql);
        $screen['course_units'] = array_column($res2, 'course_units');
        $screen['type'] = array_column((new AttendType)->getAll(), 1);
        exit(retJson('请求成功', true, $screen));
    }

    public function feedbackScreen() {
        $sql = "SELECT dept_name FROM db_student_feedback WHERE dept_name IS NOT NULL GROUP BY dept_name ";
        $res1 = $this->Student_feedback_record_model->query($sql);
        $sql = "SELECT dept_name FROM db_supervisor_feedback WHERE dept_name IS NOT NULL GROUP BY dept_name ";
        $res2 = $this->Supervisor_feedback_record_model->query($sql);
        $screen['dept_name'] = array_keys(array_flip(array_column($res1, 'dept_name')) + array_flip(array_column($res2, 'dept_name')));
        exit(retJson('请求成功', true, $screen));
    }
}
